package cn.edu.scau.cmi.ChenKaihui.composite.consistent;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class ConsistentClient extends Application{

	@FXML
	private TextArea ComArea;
	@FXML
	private TextArea LeafArea;
	
	
	//ConsistentComposite
	ConsistentComposite CEO = new ConsistentComposite("ZhangSan");
			
	ConsistentComposite headSales = new ConsistentComposite("LiSi");
	ConsistentComposite headMarketing = new ConsistentComposite("WangWu");
	
	@FXML
	public void comAdd() {
		CEO.addChild(headSales);
		ComArea.appendText("成功添加下级员工:  " + headSales.getName() +"\n");
	    CEO.addChild(headMarketing);
	    ComArea.appendText("成功添加下级员工:  " + headMarketing.getName() +"\n");
	}
	
	@FXML
	public void comDel() {
		CEO.delete(headSales);
		ComArea.appendText("成功删除下级员工:  " + headSales.getName() +"\n");
		CEO.delete(headMarketing);
		ComArea.appendText("成功删除下级员工:  " + headMarketing.getName() +"\n");
	}
		 
    //ConsistentLeaf
	ConsistentLeaf clerk = new ConsistentLeaf("XiaoMing");
	
	@FXML
	public void leafAdd() {
		clerk.addChild(headSales);
		LeafArea.appendText("对不起，最低一级员工(叶子节点)不能添加下属\n");
	}
	
	@FXML
	public void leafDel() {
		clerk.delete(headMarketing);
		LeafArea.appendText("对不起，最低一级员工(叶子节点)没有下属，无法删除\n");
	}
			
	
     public static void main(String[] args) {
		
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("../../UI/consistentUI.fxml"));
	    primaryStage.setTitle("一致性组合模式实验");
	    primaryStage.setScene(new Scene(root, 535, 530));
	    primaryStage.setResizable(false);
	    primaryStage.show();
		
	}
	
}
